package cz.proks.easyhelpdesk.gae.api.impl.ws;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cz.proks.easyhelpdesk.api.UserApi;
import cz.proks.easyhelpdesk.api.config.Configuration;
import cz.proks.easyhelpdesk.api.exception.ApiException;
import cz.proks.easyhelpdesk.api.model.User;

@Controller(Configuration.WS.USER_API)
@RequestMapping(Configuration.WS.USER_BASE_URL)
public class UserApiImpl extends BaseApiImpl<User> implements UserApi {
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	@Qualifier(Configuration.Core.WS.USER_API)
	private UserApi coreApi;

	@Override
	protected UserApi getCoreApi() {
		return coreApi;
	}

    @Override
    @RequestMapping(value="/getForProvider/{providerId}", method = RequestMethod.GET)
    @ResponseBody    
    public User getForProvider(@PathVariable String providerId) throws ApiException {        
        log.debug("getForProvider():: Start with providerId '{}'", providerId);
        
        User user = getCoreApi().getForProvider(providerId);
        
        log.debug("getForProvider():: Exit with entity '{}'", user);
        return user;
    }		
    
    @Override
    @RequestMapping(value="/listForHeldpesk/{helpdeskId}", method = RequestMethod.GET)
    @ResponseBody    
    public List<User> listForHelpdesk(@PathVariable Long helpdeskId) throws ApiException {
        log.debug("listForHelpdesk():: Start with helpdeskId '{}'", helpdeskId);
        
        List<User> users = getCoreApi().listForHelpdesk(helpdeskId);
        
        log.debug("listForHelpdesk():: Exit with {}", (users == null ? "null list" : "list of " + users.size() + " members"));
        return users;
    }        
}
